In [6]:
from pyteltools.geom import Shapefile
from pyteltools.slf.interpolation import MeshInterpolator
from pyteltools.slf import Serafin
points = [(97.0, 32.5), (97.5, 33.5)]
with Serafin.Read('../scripts_PyTelTools_validation/data/Yen/fis_yen-exp.slf', 'en') as resin:
resin.read_header()
resin.get_time()
# Determine mesh interpolation
mesh = MeshInterpolator(resin.header, True)
is_inside, point_interpolators = mesh.get_point_interpolators(points)
nb_inside = sum(map(int, is_inside))
print("%i points are inside the mesh" % nb_inside)
# Interpolate one variable (BOTTOM) and one frame only (the last)
values = resin.read_var_in_frame(0, 'S')
results = []
for pt_id, (point, point_interpolator) in enumerate(zip(points, point_interpolators)):
if point_interpolator is not None:
(i, j, k), interpolator = point_interpolator
results.append(interpolator.dot(values[[i, j, k]]))
print(results)